﻿using System;
using System.Collections.Generic;
using System.Web;
using NewThinkings.BusinessLayer.BusinessObject;
using NewThinkings.BusinessLayer.Facade.Core;
using NewThinkings.BusinessLayer.BusinessObject.Core;

namespace Presentation.WebApp.Mods.Front.Services
{
    /// <summary>
    /// Summary description for TreeFunction
    /// </summary>
    public class TreeFunction : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string itemType = context.Request.Form["itemType"].ToString();//context.Request.QueryString["id"];
            int id = int.Parse(context.Request.Form["id"].ToString());
            if (itemType == "App")
                context.Response.Write(GetModuleByAppID(id));
            else
            {
                context.Response.Write(GetInterfaceFunc(id));
            }

        }
        public string GetModuleByAppID(int idApp)
        {
            string ret = string.Empty;
            //CSession session = new CSession();
            //if (session.IsAuthenticated)
            //{
            IList<CModule> listModule = new CCoreFacade().GetModuleByUserID(string.Format("<InputValue UserID=\"1\" ApplicationID=\"{0}\" Session=\"ABCD-EFGHIJK-LMNPQR-STUV\" FunctionID=\"1\" />",idApp));
            ret = CModuleUI.GetHtml(listModule);
            //}
         
            return ret;
        }

        public string GetInterfaceFunc(int IdModule)
        {
            string ret = "";
            //CSession session = new CSession();
            //if (session.IsAuthenticated)
            //{
            IList<CInterfaceFunction> listFunc = new CCoreFacade().GetInterfaceFunctionByUserID(string.Format("<InputValue UserID=\"1\" ModuleID=\"{0}\" Session=\"ABCD-EFGHIJK-LMNPQR-STUV\" FunctionID=\"1\" />", IdModule));
            ret = CInterfaceFunctionUI.GetHtml(listFunc);
            //}
            return ret;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}